<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/classes/smarty/plugins/function.messages.php, $Author:  $ */

/** Display block for message and error.
 * Parameters:
 *  - template [optional] - template path (by default - '_default')
 *  - title [optional] - block title (not all template support this)
 */
function smarty_function_messages($params, &$smarty)
{
    $sRes = '';

    $sName = isset($params['block']) ? $params['block'] : '_default';

	$sTemplate = isset($params['template']) ? $params['template'] : '_blocks/messages.html';
	if ('/' != substr($sTemplate, 0, 1))
	{
	    $sTemplate = App::getParam('template', 'dir').'/'. App::getLayout() .'/'.$sTemplate;
	}
	$smarty->assignSrc('_aMessages', array());

	if (isset($_SESSION['_messages'][App::getPageName()][$sName]))
	{
	    $smarty->assignSrc('_aMessages', $_SESSION['_messages'][App::getPageName()][$sName]);
		unset($_SESSION['_messages'][App::getPageName()][$sName]);
	}
	if (isset($params['error_var']))
	{
	    $aErrors = $smarty->get_template_vars($params['error_var']);
	    if ($aErrors)
	    {
		    $smarty->assign('aErrors', $aErrors);
	    }
	}

	//block title and other params
	$smarty->assign('sBlockTitle', isset($params['title']) ? $params['title'] : '');
	$smarty->assign('aParams', $params);

	$sRes = $smarty->fetch($sTemplate);

	if (isset($params['error_var']))
	{
	    $smarty->assign('aErrors', null);
	}
    return $sRes;
}
?>